Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(WIP) feat: LWE #177

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

(WIP) feat: LWE #177

wants to merge 2 commits into from

Conversation

Autoparallel
Copy link
Contributor

@Autoparallel Autoparallel commented Dec 23, 2024

WIP

  • Basic LWE
  • Ring-LWE
  • Improve API (take bytes for Plaintext?)
  • Improve documentation
  • Better testing

@Autoparallel
Copy link
Contributor Author

I can't replicate the failing test locally. Maybe an issue with toolchain?

@mrdaybird
Copy link
Contributor

I can't replicate the failing test locally. Maybe an issue with toolchain?

Maybe rerun the tests, weil_from_test_pairing test occasionally fails for me as well, not sure why though.

@Autoparallel
Copy link
Contributor Author

It's so odd. Drives me kinda crazy.

@Autoparallel Autoparallel marked this pull request as ready for review January 1, 2025 14:33
Copy link
Contributor

@mrdaybird mrdaybird left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍
Would love to see it work for larger messages!

Comment on lines +156 to +162
let dist_to_q_half = if result >= q_half {
// If result ≥ q/2, distance is min(result - q/2, q - result + q/2)
(result - q_half).min(-result + q_half)
} else {
// If result < q/2, distance is min(q/2 - result, result + q/2)
(q_half - result).min(result + q_half)
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed?
I think (result - q_half) <= (-result + q_half) for result >= q_half, and (q_half - result) <= (result + q_half) for result < q_half, is always true. I also did a quick check if this is ever not true for test_encryption_decryption.

Maybe you could verify this?

Maybe this could be distilled to:

Suggested change
let dist_to_q_half = if result >= q_half {
// If result ≥ q/2, distance is min(result - q/2, q - result + q/2)
(result - q_half).min(-result + q_half)
} else {
// If result < q/2, distance is min(q/2 - result, result + q/2)
(q_half - result).min(result + q_half)
};
let dist_to_q_half = (result - q_half).min(q_half - result);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants